package com.fc.campusapplicationsystem.controller;

import com.fc.campusapplicationsystem.model.Consumer;
import com.fc.campusapplicationsystem.model.Serviceman;
import com.fc.campusapplicationsystem.model.Superuser;
import com.fc.campusapplicationsystem.util.WebUtil;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;

/**
 * @Author:蒋凌鹏
 * @Date:2020/3/3
 * @Explain:campusapplicationsystem
 * 系统Controller 只做跳转
 */
@Controller
@RequestMapping("/sys")
public class SystemController {


    /**
     * 登录页
     * @return
     */
    @GetMapping("/login")
    public String login(){
        return "login";
    }



    /**
     * 管理员首页
     * @return
     */
    @GetMapping("/admin")
    public String adminIndex(){
        Superuser superuser = (Superuser) WebUtil.getSession().getAttribute("superuser");
        return superuser != null ? "admin/admin_index" : "login";

    }

    /**
     * 用户首页
     * @return
     */
    @GetMapping("/user")
    public String userIndex(){
        Consumer consumer = (Consumer) WebUtil.getSession().getAttribute("consumer");
        return consumer != null ? "user/user_index" : "login";
    }


    /**
     * 维修人员首页
     * @return
     */
    @GetMapping("/serviceman")
    public String repairIndex(){
        Serviceman serviceman = (Serviceman) WebUtil.getSession().getAttribute("serviceman");
        if (serviceman != null){
            return "repair/repair_index";
        }  else {
            return "login";
        }

    }




    /**
     * 退出系统
     */
    @GetMapping("/signOut")
    public String signOut(){
        WebUtil.getSession().setAttribute("consumer",null);
        WebUtil.getSession().setAttribute("superuser",null);
        WebUtil.getSession().setAttribute("serviceman",null);
        return "login";
    }
}
